package il.ac.bgu.cs.heuristics.core;

import il.ac.bgu.cs.heuristics.graph.types.IState;

import java.util.ArrayList;

public class Monitor implements IMonitor {

	public class StringInfoPair {
		String		mMsg;
		InfoType	mInfo;

		StringInfoPair(String msg, InfoType info) {
			mMsg = msg;
			mInfo = info;

		}

	}

	private final ArrayList<StringInfoPair>	mStringList;
	private long							mRecursiveCallCounter;
	private final ArrayList<Long>			mRecursiveCallDepot;

	public Monitor() {
		mStringList = new ArrayList<StringInfoPair>();
		mRecursiveCallDepot = new ArrayList<Long>();
		mRecursiveCallCounter = 0;
	}

	public void enqueueMsg(String msg, InfoType type) {
		mStringList.add(new StringInfoPair(msg, type));
	}

	public void enterMethod(String MethodName) {
		enqueueMsg(MethodName, InfoType.ENTER_METHOD);
	}

	public void leaveMethod(String MethodName) {
		enqueueMsg(MethodName, InfoType.LEAVE_METHOD);
	}

	@Override
	public void addRecursiveCall() {
		mRecursiveCallCounter++;

	}

	@Override
	public void saveRecursiveCalls() {
		mRecursiveCallDepot.add(mRecursiveCallCounter);
		mRecursiveCallCounter = 0;
	}

	@Override
	public void enterGetHValue(IState init, IState goal) {
		enqueueMsg("init: " + init.toString() + " goal: " + goal.toString(),
				InfoType.GETHVALUE_ACCESS);
	}

	public void leaveGetHValue(int hvalue) {
		enqueueMsg("leave GetHValue hvalue is: " + Integer.toString(hvalue),
				InfoType.GETHVALUE_ACCESS);
	}

}
